﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;

namespace JTicket.Common
{
    ///javascript脚本
    /// </summary>
    public class JsMsg
    {
        protected static HttpResponse Response;
        protected static HttpSessionState Session;
        /// <summary>
        /// 刷新父窗口
        /// </summary>
        public static void RefreshParent()
        {
            string js = @"<Script language='JavaScript'>
                    parent.location.reload();
                  </Script>";
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        /// 刷新打开窗口
        /// </summary>
        public static void RefreshOpener()
        {
            string js = @"<Script language='JavaScript'>
                    opener.location.reload();
                  </Script>";
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        /// 打开窗口
        /// </summary>
        /// <param name="url"></param>
        public static void OpenWebForm(string url)
        {

            /*…………………………………………………………………………………………*/
            /*修改人员:			*/
            /*修改时间:		*/
            /*修改目的:	新开页面去掉ie的菜单。。。						*/
            /*注释内容:								*/
            /*开始*/
            string js = @"<Script language='JavaScript'>
			//window.open('" + url + @"');
			window.open('" + url + @"','','left=310,top=120,width=379,height=142,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,directories=no');
			</Script>";
            /*结束*/
            /*…………………………………………………………………………………………*/
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        /// 新开页面去掉ie的菜单。。。
        /// </summary>
        /// <param name="url"></param>
        /// <param name="formName"></param>
        public static void OpenWebForm(string url, string formName)
        {
            /*…………………………………………………………………………………………*/
            /*修改人员:							*/
            /*修改时间:	
            /*修改目的:	新开页面去掉ie的菜单。。。						*/
            /*注释内容:								*/
            /*开始*/
            string js = @"<Script language='JavaScript'>
			//window.open('" + url + @"','" + formName + @"');
			window.open('" + url + @"','" + formName + @"','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');
			</Script>";
            /*结束*/
            /*…………………………………………………………………………………………*/

            HttpContext.Current.Response.Write(js);
        }
        /// <summary>		
        /// 函数名:OpenWebForm	
        /// 功能描述:打开WEB窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="url">WEB窗口</param>
        /// <param name="isFullScreen">是否全屏幕</param>
        /// <param name="status">是否显示菜单</param>
        public static void OpenWebForm(string url, bool isFullScreen, bool status)
        {
            string js = @"<Script language='JavaScript'>";
            if (isFullScreen)
            {
                js += "var iWidth = 0;";
                js += "var iHeight = 0;";
                js += "iWidth=window.screen.availWidth-10;";
                js += "iHeight=window.screen.availHeight-50;";
                js += "var szFeatures ='width=' + iWidth + ',height=' + iHeight + ',top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,directories=no';";
                js += "window.open('" + url + @"','',szFeatures);";
            }
            else
            {
                js += "window.open('" + url + @"','','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');";
            }
            js += "</Script>";
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>		
        /// 函数名:OpenWebForm	
        /// 功能描述:打开WEB窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="url">WEB窗口</param>
        /// <param name="isFullScreen">是否全屏幕</param>
        public static void OpenWebForm(string url, bool isFullScreen)
        {
            string js = @"<Script language='JavaScript'>";
            if (isFullScreen)
            {
                js += "var iWidth = 0;";
                js += "var iHeight = 0;";
                js += "iWidth=window.screen.availWidth-10;";
                js += "iHeight=window.screen.availHeight-50;";
                js += "var szFeatures ='width=' + iWidth + ',height=' + iHeight + ',top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no';";
                js += "window.open('" + url + @"','',szFeatures);";
            }
            else
            {
                js += "window.open('" + url + @"','','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');";
            }
            js += "</Script>";
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        /// 转向Url制定的页面
        /// </summary>
        /// <param name="url"></param>
        public static void JavaScriptLocationHref(string url)
        {
            string js = @"<Script language='JavaScript'>
                    window.location.replace('{0}');
                  </Script>";
            js = string.Format(js, url);
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        /// 指定的框架页面转换
        /// </summary>
        /// <param name="FrameName"></param>
        /// <param name="url"></param>
        public static void JavaScriptFrameHref(string FrameName, string url)
        {
            string js = @"<Script language='JavaScript'>
					
                    @obj.location.replace(""{0}"");
                  </Script>";
            js = js.Replace("@obj", FrameName);
            js = string.Format(js, url);
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        ///重置页面
        /// </summary>
        public static void JavaScriptResetPage(string strRows)
        {
            string js = @"<Script language='JavaScript'>
                    window.parent.CenterFrame.rows='" + strRows + "';</Script>";
            HttpContext.Current.Response.Write(js);
        }
        /// <summary>
        /// 函数名:JavaScriptSetCookie
        /// 功能描述:客户端方法设置Cookie
        /// 作者:
        /// 日期：
        /// 版本：
        /// </summary>
        /// <param name="strName">Cookie名</param>
        /// <param name="strValue">Cookie值</param>
        public static void JavaScriptSetCookie(string strName, string strValue)
        {
            string js = @"<script language=Javascript>
			var the_cookie = '" + strName + "=" + strValue + @"'
			var dateexpire = 'Tuesday, 01-Dec-2020 12:00:00 GMT';
			//document.cookie = the_cookie;//写入Cookie<BR>} <BR>
			document.cookie = the_cookie + '; expires='+dateexpire;			
			</script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>		
        /// 函数名:GotoParentWindow	
        /// 功能描述:返回父窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 2003-04-30 10:00
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="parentWindowUrl">父窗口</param>		
        public static void GotoParentWindow(string parentWindowUrl)
        {
            string js = @"<Script language='JavaScript'>
                    this.parent.location.replace('" + parentWindowUrl + "');</Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>		
        /// 函数名:ReplaceParentWindow	
        /// 功能描述:替换父窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 2003-04-30 10:00
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="parentWindowUrl">父窗口</param>
        /// <param name="caption">窗口提示</param>
        /// <param name="future">窗口特征参数</param>
        public static void ReplaceParentWindow(string parentWindowUrl, string caption, string future)
        {
            string js = "";
            if (future != null && future.Trim() != "")
            {
                js = @"<script language=javascript>this.parent.location.replace('" + parentWindowUrl + "','" + caption + "','" + future + "');</script>";
            }
            else
            {
                js = @"<script language=javascript>var iWidth = 0 ;var iHeight = 0 ;iWidth=window.screen.availWidth-10;iHeight=window.screen.availHeight-50;
							var szFeatures = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';this.parent.location.replace('" + parentWindowUrl + "','" + caption + "',szFeatures);</script>";
            }

            HttpContext.Current.Response.Write(js);
        }
        /// <summary>		
        /// 函数名:ReplaceOpenerWindow	
        /// 功能描述:替换当前窗体的打开窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 2003-04-30 16:00
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="openerWindowUrl">当前窗体的打开窗口</param>		
        public static void ReplaceOpenerWindow(string openerWindowUrl)
        {
            string js = @"<Script language='JavaScript'>
                    window.opener.location.replace('" + openerWindowUrl + "');</Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>		
        /// 函数名:ReplaceOpenerParentWindow	
        /// 功能描述:替换当前窗体的打开窗口的父窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 2003-07-03 19:00
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>		
        public static void ReplaceOpenerParentFrame(string frameName, string frameWindowUrl)
        {
            string js = @"<Script language='JavaScript'>
                    window.opener.parent." + frameName + ".location.replace('" + frameWindowUrl + "');</Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>		
        /// 函数名:ReplaceOpenerParentWindow	
        /// 功能描述:替换当前窗体的打开窗口的父窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>		
        public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)
        {
            string js = @"<Script language='JavaScript'>
                    window.opener.parent.location.replace('" + openerParentWindowUrl + "');</Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>		
        /// 函数名:CloseParentWindow	
        /// 功能描述:关闭窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 2003-04-30 16:00
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        public static void CloseParentWindow()
        {
            string js = @"<Script language='JavaScript'>
                    window.parent.close();  
                  </Script>";
            HttpContext.Current.Response.Write(js);
        }

        public static void CloseOpenerWindow()
        {
            string js = @"<Script language='JavaScript'>
                    window.opener.close();  
                  </Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>
        /// 函数名:ShowModalDialogJavascript	
        /// 功能描述:返回打开模式窗口的脚本	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="webFormUrl"></param>
        /// <returns></returns>
        public static string ShowModalDialogJavascript(string webFormUrl)
        {
            string js = @"<script language=javascript>
							var iWidth = 0 ;
							var iHeight = 0 ;
							iWidth=window.screen.availWidth-10;
							iHeight=window.screen.availHeight-50;
							var szFeatures = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';
							showModalDialog('" + webFormUrl + "','',szFeatures);</script>";
            return js;
        }

        public static string ShowModalDialogJavascript(string webFormUrl, string features)
        {
            string js = @"<script language=javascript>							
							showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
            return js;
        }

        /// <summary>
        /// 函数名:ShowModalDialogWindow	
        /// 功能描述:打开模式窗口	
        /// 处理流程:
        /// 算法描述:
        /// 作 者: 
        /// 日 期: 
        /// 修 改:
        /// 日 期:
        /// 版 本:
        /// </summary>
        /// <param name="webFormUrl"></param>
        /// <returns></returns>
        public static void ShowModalDialogWindow(string webFormUrl)
        {
            string js = ShowModalDialogJavascript(webFormUrl);
            HttpContext.Current.Response.Write(js);
        }

        public static void ShowModalDialogWindow(string webFormUrl, string features)
        {
            string js = ShowModalDialogJavascript(webFormUrl, features);
            HttpContext.Current.Response.Write(js);
        }
        public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
        {
            string features = "dialogWidth:" + width.ToString() + "px"
                + ";dialogHeight:" + height.ToString() + "px"
                + ";dialogLeft:" + left.ToString() + "px"
                + ";dialogTop:" + top.ToString() + "px"
                + ";center:yes;help=no;resizable:no;status:no;scroll=no";
            ShowModalDialogWindow(webFormUrl, features);
        }

        public static void SetHtmlElementValue(string formName, string elementName, string elementValue)
        {
            string js = @"<Script language='JavaScript'>if(document." + formName + "." + elementName + "!=null){document." + formName + "." + elementName + ".value =" + elementValue + ";}</Script>";
            HttpContext.Current.Response.Write(js);
        }

        /// <summary>
        /// 判断Session中某键值是否存在，如果不存在，输出提示信息
        /// 并且转向相应页面
        /// </summary>
        /// <param name="SessionName">Session中键名称</param>
        /// <param name="Message">提示信息</param>
        /// <param name="RedirectUrl">要转向的页面</param>
        public static void CheckSession(string SessionName, string Message, string RedirectUrl)
        {
            Session = HttpContext.Current.Session;
            Response = HttpContext.Current.Response;
            if (Session[SessionName] == null)
            {
                WriteMessage(Message, false, false);
                string js = "top.document.location='" + RedirectUrl + "';";
                WriteJavaScript(js); ;
            }
        }

        /// <summary>
        /// 用Javascript的Window.alert()方法输出提示信息
        /// </summary>
        /// <param name="strMsg">要输出的信息</param>
        /// <param name="Back">输出信息后是否要history.back()</param>
        /// <param name="End">输出信息后是否要Response.end()</param>
        public static void WriteMessage(string strMsg, bool Back, bool End)
        {
            Response = HttpContext.Current.Response;
            //将单引号替换，防止javascript出错
            strMsg = strMsg.Replace("'", "“");
            //将回车换行符去掉，防止javascript出错
            strMsg = strMsg.Replace("\r\n", "");
            Response.Write("<script language=javascript>alert('" + strMsg + "');</script>");
            if (Back)
                Response.Write("<script language=javascript>history.back();</script>");
            if (End)
                Response.End();
        }

        /// <summary>
        /// 以Response.Write()方式输出一条JavaScript语句
        /// </summary>
        /// <param name="strJavaScript">要输出的JavaScript语句</param>
        public static void WriteJavaScript(string strJavaScript)
        {
            Response = HttpContext.Current.Response;
            Response.Write("<script language=javascript>" + strJavaScript + "</script>");
        }

        /**/
        /// <summary>
        /// 客户端打开窗口
        /// </summary>
        /// <param name="strUrl"></param>
        public static void OpenWindow(string strUrl)
        {
            HttpContext.Current.Response.Write("<script language=javascript>");
            HttpContext.Current.Response.Write("window.open('" + strUrl + "');");
            HttpContext.Current.Response.Write("</script>");
        }
        /**/
        /// <summary> 
        /// 输出自定义脚本信息 
        /// </summary> 
        /// <param name="page">当前页面指针，一般为this</param> 
        /// <param name="script">输出脚本</param> 
        public static void ResponseScript(System.Web.UI.Page page, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");
        }
        /**/
        /// <summary> 
        /// 显示消息提示对话框，并进行页面跳转 
        /// </summary> 
        /// <param name="page">当前页面指针，一般为this</param> 
        /// <param name="msg">提示信息</param> 
        /// <param name="url">跳转的目标URL</param> 
        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("top.location.href='{0}'", url);
            Builder.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
        }
        /**/
        /// <summary>
        /// 显示确认框
        /// </summary>
        /// <param name="Control">控件</param>
        /// <param name="msg">内容</param>
        public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
        {
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }
        /**/
        /// <summary>
        /// 清空所有panel里面的textbox内容
        /// </summary>
        /// <param name="pan"></param>
        public static void clearAll(System.Web.UI.WebControls.Panel pan)
        {
            foreach (Control panl in pan.Controls)
            {
                if (panl.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                {
                    ((System.Web.UI.WebControls.TextBox)panl).Text = "";
                }
            }
        }
        /**/
        /// <summary>
        ///  窗体加载以后探出对话框
        ///  </summary>
        public static void Alert(string msg)
        {
            Page pages;
            pages = HttpContext.Current.Handler as System.Web.UI.Page;
            msg = msg.Replace("'", "");
            msg = msg.Replace("\"", "");
            msg = msg.Replace("\n", @"\n").Replace("\r", @"\r").Replace("\"", @"\""");
            pages.Controls.Add(new System.Web.UI.LiteralControl("<script language=javascript>alert('" + msg + "');</script>"));
        }
        /**/
        /// <summary>
        /// 窗体没有加载的时候如pageload的时候探出对话框
        /// </summary>
        public static void Alert_none(string msg)
        {
            Page pages;
            pages = HttpContext.Current.Handler as System.Web.UI.Page;
            msg = msg.Replace("'", "");
            msg = msg.Replace("\"", "");
            msg = msg.Replace("\n", @"\n").Replace("\r", @"\r").Replace("\"", @"\""");
            string retu = " alert('" + msg + "');";
            ClientWrite2(retu);
        }
        /**/
        /// <summary>
        /// 加载以后写自己的脚本
        /// </summary>
        /// <param name="pages"></param>
        /// <param name="yourJs"></param>
        public static void ClientWrite(string yourJs)
        {
            Page pages;
            pages = HttpContext.Current.Handler as System.Web.UI.Page;
            pages.Controls.Add(new System.Web.UI.LiteralControl("<script language=javascript>" + yourJs + "</script>"));
        }
        /**/
        /// <summary>
        /// 加载以前写自己的脚本
        /// </summary>
        /// <param name="pages"></param>
        /// <param name="yourJs"></param>
        public static void ClientWrite2(string yourJs)
        {
            Page pages;
            pages = HttpContext.Current.Handler as System.Web.UI.Page;
            pages.Response.Write("<script language=javascript>");
            pages.Response.Write(yourJs);
            pages.Response.Write(" </script>");
        }
        /**/
        /// <summary>
        /// 得到刷新界面的字符串
        /// </summary>
        /// <returns></returns>
        public static string RefreshWin()
        {
            return "window.location=window.location.href;";
        }
        /**/
        /// <summary>
        /// 打开小窗体
        /// </summary>
        /// <param name="url"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="top"></param>
        /// <param name="left"></param>
        public static void OpenLittleWindow(string url, int width, int height, int top, int left)
        {
            string str;
            str = "javascript:var popup;popup=window.open('{url}',null,'scrollbars=yes,status=no,width={width},height={height},top={top},left={left}');popup.opener=self.opener;self.close();";
            str = str.Replace("{width}", width.ToString());
            str = str.Replace("{height}", height.ToString());
            str = str.Replace("{top}", top.ToString());
            str = str.Replace("{left}", left.ToString());
            str = str.Replace("{url}", url);
        }
        /**/
        /// <summary>
        /// 回车-〉tab
        /// </summary>
        public static void ToTab()
        {
            Page page;
            page = HttpContext.Current.Handler as System.Web.UI.Page;
            System.Text.StringBuilder scriptFunction = new StringBuilder();
            scriptFunction.Append("<script language='javascript'>");
            scriptFunction.Append("       function returnTotab()");
            scriptFunction.Append("         {");
            scriptFunction.Append("          if(event.keyCode==13)    ");
            scriptFunction.Append("             {event.keyCode=9;     ");
            scriptFunction.Append("               return true;}       ");
            scriptFunction.Append("          } ");
            scriptFunction.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "totab", scriptFunction.ToString());

        }
        /**/
        /// <summary>
        /// tab->enter
        /// </summary>
        public static void tabToEnter()
        {
            Page page;
            page = HttpContext.Current.Handler as System.Web.UI.Page;
            System.Text.StringBuilder scriptFunction = new StringBuilder();
            scriptFunction.Append("<script language='javascript'>");
            scriptFunction.Append("    function Tcheck()");
            scriptFunction.Append("         {");
            scriptFunction.Append("         if(event.keyCode==8||event.keyCode==9) ");
            scriptFunction.Append("          return true;");
            scriptFunction.Append("         else ");
            scriptFunction.Append("         {");
            scriptFunction.Append("          if(((event.keyCode>=48)++(event.keyCode<=57))||((event.keyCode>=96)++(event.keyCode<=105)))");
            scriptFunction.Append("              return true;");
            scriptFunction.Append("          else");
            scriptFunction.Append("          if(event.keyCode==13||event.keyCode==110||event.keyCode==190||event.keyCode==39)");
            scriptFunction.Append("             {event.keyCode=9;");
            scriptFunction.Append("               return true;}");
            scriptFunction.Append("            else");
            scriptFunction.Append("              return false;");
            scriptFunction.Append("        }");
            scriptFunction.Append("          }     ");
            scriptFunction.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "switch", scriptFunction.ToString());
        }
        /**/
        /// <summary>
        /// attachEvent
        /// </summary>
        /// <param name="controlToFocus"></param>
        /// <param name="page"></param>
        public static void attachEvent(Control[] controlToFocus)
        {
            Page page;
            page = HttpContext.Current.Handler as System.Web.UI.Page;
            System.Text.StringBuilder scriptFunction = new StringBuilder();
            string scriptClientId;
            scriptFunction.Append("<script language='javascript'>");

            foreach (Control con in controlToFocus)
            {
                scriptClientId = con.ClientID;
                scriptFunction.Append("document.getElementById('" + scriptClientId + "').attachEvent('onkeydown', Tcheck);");
            }
            scriptFunction.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "attach", scriptFunction.ToString());
        }
        /**/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="controlToFocus"></param>
        /// <param name="page"></param>
        /// <param name="eventStr"></param>
        /// <param name="FuncStr"></param>
        public static void AttachEvent(Control[] controlToFocus, string eventStr, string FuncStr)
        {
            Page page;
            page = HttpContext.Current.Handler as System.Web.UI.Page;
            System.Text.StringBuilder scriptFunction = new StringBuilder();
            string scriptClientId;
            scriptFunction.Append("<script language='javascript'>");
            foreach (Control con in controlToFocus)
            {
                scriptClientId = con.ClientID;
                scriptFunction.Append("document.getElementById('" + scriptClientId + "').attachEvent('" + eventStr + "', " + FuncStr + ");");
            }
            scriptFunction.Append("</script>");
            page.ClientScript.RegisterStartupScript(page.GetType(), "attach2", scriptFunction.ToString());
        }
        /**/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"> </param>
        public static void NumOnlyFun()
        {
            Page page;
            page = HttpContext.Current.Handler as System.Web.UI.Page;
            System.Text.StringBuilder scriptFunction = new StringBuilder();
            scriptFunction.Append("<script language='javascript'>");
            scriptFunction.Append("       function isNum()");
            scriptFunction.Append("         {");
            scriptFunction.Append("              if(event.keyCode==8||event.keyCode==9) ");
            scriptFunction.Append("                  return true;");
            scriptFunction.Append("             else ");
            scriptFunction.Append("             {");
            scriptFunction.Append("          if(((event.keyCode>=48)++(event.keyCode<=57))||((event.keyCode>=96)++(event.keyCode<=105)))");
            scriptFunction.Append("              return true;");
            scriptFunction.Append("          else");
            scriptFunction.Append("                return false;");
            scriptFunction.Append("        }");
            scriptFunction.Append("          } ");
            scriptFunction.Append("</script>");
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "numonly", scriptFunction.ToString());
        }
        #region ""
        /// <summary>
        /// 注册提示客户端脚本，并返回上一步
        /// </summary>
        /// <param name="pScript">脚本</param>
        /// <param name="pKey">键值</param>
        public static void RegisterAlertAndBackScript(string pMessage, string pKey, Page pPage)
        {
            string Script = @"alert('" + pMessage + @"');history.back();";
            pPage.ClientScript.RegisterClientScriptBlock(pPage.GetType(), pPage.UniqueID + pKey,
            Script, true);
        }
        /// <summary>
        /// 注册提示客户端脚本
        /// </summary>
        /// <param name="pScript">脚本</param>
        /// <param name="pKey">键值</param>
        public static void RegisterAlertScript(string pMessage, string pNavigateTo, string pKey, Page pPage)
        {
            string Script = @"alert('" + pMessage + @"');window.navigate('" + pNavigateTo + @"');";
            pPage.ClientScript.RegisterClientScriptBlock(pPage.GetType(), pPage.UniqueID + pKey,
            Script, true);
        }
        /// <summary>
        /// 注册提示客户端脚本
        /// </summary>
        /// <param name="pScript">脚本</param>
        /// <param name="pKey">键值</param>
        public static void RegisterConfirmScript(string pMessage, string pYesNavigateTo, string pNoNavigateTo, string pKey, Page pPage)
        {
            string Script = @"if(confirm('" + pMessage + @"'))
                      window.navigate('" + pYesNavigateTo + @"');
                    else
                      window.navigate('" + pNoNavigateTo + @"')";
            pPage.ClientScript.RegisterClientScriptBlock(pPage.GetType(), pPage.UniqueID + pKey,
            Script, true);
        }
        /// <summary>
        /// 弹出脚本对话框
        /// </summary>
        /// <param name="_Msg">对话框显示内容</param>
        /// <param name="_page">web窗体页面</param>
        /// <returns>脚本对话框</returns>
        public static string MsgBoxAler(string _Msg, Page _page)
        {
            string _M = _Msg;
            Page _P = _page;
            string StrScript;
            StrScript = ("<script language=javascript>");
            StrScript += ("alert('" + _M + "');");
            StrScript += ("</script>");
            _P.ClientScript.RegisterClientScriptBlock(_P.GetType(), "MsgBox", StrScript.ToString());

            return StrScript;
        }
        /// <summary>
        /// 弹出小窗口
        /// </summary>
        /// <param name="_MsgPage">弹出的页面</param>
        /// <param name="_dav">显示文字</param>
        /// <param name="_Width">宽</param>
        /// <param name="_height">高</param>
        /// <param name="_page"></param>
        /// <returns></returns>
        public static string MsgSmallWindow(string _MsgPage, string _dav, int _Width, int _height, Page _page)
        {
            string _M = _MsgPage;
            Page _P = _page;
            string _d = _dav;
            int _W = _Width;
            int _H = _height;
            string StrScript;
            StrScript = ("<script language=javascript>");
            StrScript += "window.showModalDialog(\"" + _MsgPage + "\",\"" + _dav + "\",\"dialogHeight: " + _height + "px;   dialogWidth:   " + _Width + "px\");";
            StrScript += ("</script>");
            _P.ClientScript.RegisterClientScriptBlock(_P.GetType(), "MsgSmallWindow", StrScript.ToString());

            return StrScript;

        }
        /// <summary>
        /// 弹出脚本确定框
        /// </summary>
        /// <param name="_MsgC">确定框显示的内容</param>
        /// <param name="URL">定位页面地址</param>
        /// <param name="_page">web窗体页面</param>
        /// <returns>脚本确定框</returns>
        public static string MsgBoxConfirm(string _MsgC, string URL, Page _page)
        {

            string _M = _MsgC;
            Page _P = _page;
            string _U = URL;
            string StrScript;
            StrScript = ("<script language=javascript>");
            StrScript += "var retValue=window.confirm('" + _MsgC + "');" + "if(retValue){window.location='" + _U + "';}";
            StrScript += ("</script>");
            _P.ClientScript.RegisterClientScriptBlock(_P.GetType(), "MsgBoxConfirm", StrScript.ToString());

            return StrScript;

        }
        /// <summary>
        /// 弹出定位脚本对话框
        /// </summary>
        /// <param name="_MsgC">对话框显示内容</param>
        /// <param name="URL">定位页面地址</param>
        /// <param name="_page">web窗体页面</param>
        /// <returns>脚本对话框</returns>   
        public static string MsgBoxRedrect(string _MsgC, string URL, Page _page)
        {

            string _M = _MsgC;
            Page _P = _page;
            string _U = URL;
            string StrScript;


            StrScript = ("<script language=javascript>");
            StrScript += ("alert('" + _M + "');");
            StrScript += ("window.location='" + _U + "';");
            StrScript += ("</script>");
            _P.ClientScript.RegisterClientScriptBlock(_P.GetType(), "MsgBoxConfirm", StrScript.ToString());

            return StrScript;
        }
        /// <summary>
        /// 关闭窗口弹出确认
        /// </summary>
        /// <param name="_MsgC">您即将离开本页面,未保存的内容将会丢失.确定要继续吗?</param>
        /// <param name="pPage"></param>
        public static string MsgCloseWindowConfirm(string _MsgC, string pKey, Page pPage)
        {
            string script = "<script language=\"JavaScript\">window.onload = function() {window.onbeforeunload = function(event) {event = window.event || event;event.returnValue='" + _MsgC + "';};};</script>";
            pPage.ClientScript.RegisterClientScriptBlock(pPage.GetType(), pKey, script);

            return script;
        }
        #endregion
    }
}
